import { http ,upload} from '@/utils/http';
import type {ArticleItem,DetailArticle,Comment} from '@/type/article'
//获取我的发布文章列表
export const API_getMyArticleList = (userId:number) => {
    return http<ArticleItem[]>({
    method: 'GET',
    url: `/article/myList?userId=${userId}`,
  })
}

//获取发现页文章
export const API_getArticleList = () => {
    return http<ArticleItem[]>({
    method: 'GET',
    url: "/article/findList",
  })
}

//点赞
export const API_giveAlike = (articleId:number,like:boolean) => {
    return http<null>({
    method: 'PUT',
    url: `/article/like?articleId=${articleId}&like=${like}`,
  })
}

//获取点赞记录或历史记录:0表示点赞记录，1表示历史记录
export const API_getLikeRecordOrHistory = (userId:number,type:number) => {
    return http<ArticleItem[]>({
    method: 'GET',
    url: `/article/likeRecordOrHistory?userId=${userId}&type=${type}`,
  })
}

//删除文章
export const API_deleteArticleItem = (articleId:number) => {
    return http<null>({
    method: 'DELETE',
    url: `/article/delete?articleId=${articleId}`,
  })
}
// 发布文章
export const API_publish = (title:string,content:string,category:number) => {
    return http<{articleId:number}>({
    method: 'POST',
    url: `/article/publish?title=${title}&content=${content}&category=${category}`,
  })
}
//上传文章图片文件
export const API_uploadImage = (category:number,categoryId:number,orderId:number,fileSrc:string) => {
    return upload<null>({
        url: `/uploadImage?category=${category}&categoryId=${categoryId}&orderId=${orderId}`,
        name: 'file',
        noLoading:true,
        filePath: fileSrc
  })
}
//发现页文章
export const API_getfindList = (type:number) => {
    return http<ArticleItem[]>({
        method: 'GET',
        url: `/article/findList?type=${type}`,
  })
}

//文章详细页
export const API_getDetailArticle = (articleId:number) => {
    return http<DetailArticle>({
        method: 'GET',
        url: `/article/detail?articleId=${articleId}`,
  })
}

//发布评论
//category:评论所属内容的类型，0 是文章 1 是八股。
export const API_addComment = (category:number,categoryId:number,commentContent:string,parentCommentId:number) => {
    return http<null>({
        method: 'POST',
        url: `/comment/addComment?category=${category}&categoryId=${categoryId}&commentContent=${commentContent}&parentCommentId=${parentCommentId}&`,
  })
}
//获取评论
export const API_getComment = (category:number,categoryId:number) => {
    return http<Comment[]>({
        method: 'GET',
        url: `/comment/getComment?category=${category}&categoryId=${categoryId}`,
  })
}